﻿Imports RegExUtility.ViewModel

Public MustInherit Class ViewCommand
    Implements ICommand
    Implements IViewModelCommand

#Region "Events"
    Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged
#End Region

#Region "Properties"
#Region "Constants"
    ' Insert Constant Declarations Here
#End Region

    Private _executeCallbackReference As Action(Of Object)
    Private Property ExecuteCallback As Action(Of Object)
        Get
            Return _executeCallbackReference
        End Get
        Set(ByVal value As Action(Of Object))
            _executeCallbackReference = value
        End Set
    End Property

    Private _executable As Boolean
    Public Property Executable As Boolean Implements IViewModelCommand.Executable
        Get
            Return _executable
        End Get
        Set(ByVal value As Boolean)
            If _executable <> value Then
                _executable = value
                RaiseEvent CanExecuteChanged(sender:=Me, e:=EventArgs.Empty)
            End If
        End Set
    End Property
#End Region

#Region "Constructors"
    Public Sub New(ByVal executeCallback As Action(Of Object), ByVal executable As Boolean)
        Me.ExecuteCallback = executeCallback
        Me.Executable = executable
    End Sub
#End Region

#Region "Methods"
    Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
        Return Me.Executable
    End Function

    Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute, IViewModelCommand.Execute
        ExecuteCallback.Invoke(parameter)
    End Sub

#Region "Event Raiser Methods"
    ' Insert Method Declarations which Raise an Event Here
#End Region

#Region "Event Handlers"
    ' Insert Method Declarations which Handle an Event Here
#End Region
#End Region

End Class